package com.qg.oss.core.aliyun;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.qg.oss.core.aliyun.client.AliyunOSSClient;
import com.qg.oss.core.aliyun.config.AliyunOSSProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author QG
 * @Date 2023/6/12 16:12
 * @description
 **/
@Configuration
@EnableConfigurationProperties(AliyunOSSProperties.class)
@ConditionalOnProperty(value = "oss.type",havingValue = "aliyun",matchIfMissing = false)
public class AliyunAutoConfiguration {

    @Autowired
    private AliyunOSSProperties aliyunOSSProperties;

    @Bean
    public OSS ossClient() {
        // 创建OSSClient实例。
        return new OSSClientBuilder().build(aliyunOSSProperties.getEndpoint(),
                aliyunOSSProperties.getAccessKeyId(),
                aliyunOSSProperties.getAccessKeySecret());
    }

    @Bean
    public AliyunOSSClient aliyunOSSClient() {
        return new AliyunOSSClient();
    }
}
